package com.itqf.vo;

/**
 * projectName: gpshop
 *
 * @author: 赵伟风
 * time: 2021/7/20 14:38
 * description:返回json结果的通用vo
 *
 * todo code = 0 通用型的请求失败
 * todo code = 1 通用型的请求成功
 */
public class R {

    private int code;
    private String msg;
    private Object data;

    public R() {
    }

    public R(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    /**
     * 成功对应的方法
     * @param msg
     * @param data
     * @return
     */
    public static  R ok(String msg,Object data){

        return new R(1,msg,data);
    }

    /**
     * 成功对应的方法,只需要填入msg数据
     * @param msg
     * @return
     */
    public static  R ok(String msg){

       return ok(msg, null);
    }

    /**
     * 成功对应的方法,什么都不需要指定!
     * @return
     */
    public static R ok(){
        return  ok(null);
    }

    /**
     * 失败返回方法封装
     * @param msg
     * @param data
     * @return
     */
    public static  R fail(String msg,Object data){

        return new R(0,msg,data);
    }


    public static  R fail(String msg){

        return R.fail(msg, null);
    }

    public static  R fail(){

        return R.fail(null);
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
